/*
package com.pearadmin.pro.common.configure;

import com.pearadmin.pro.common.secure.services.SecureUserService;
import com.pearadmin.pro.common.tools.support.server.JwtTokenEnhancer;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices;
import org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices;
import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices;
import org.springframework.security.oauth2.provider.token.*;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;

import javax.sql.DataSource;
import java.util.Arrays;

@AllArgsConstructor
@Configuration
@EnableAuthorizationServer
public class Oauth2ServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    private SecureUserService userDetailsService;
    @Autowired
    private  AuthenticationManager authenticationManager;

    @Autowired
    private AuthorizationServerTokenServices tokenServices;

    @Autowired
    private DataSource dataSource;



    // 配置客户端详情
    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        ClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource);
        ((JdbcClientDetailsService) clientDetailsService).setPasswordEncoder(passwordEncoder);
        clients.withClientDetails(clientDetailsService);// 将客户端信息存储在数据库
        */
/*clients.inMemory()// 保存在内存中，后续修改为数据库
                .withClient("client-app")// 客户端id
                .secret(passwordEncoder.encode("123456"))// 客户端密钥
                .scopes("all")// 允许的授权范围
                .autoApprove(false)// 这个是设置要不要弹出确认授权页面的
                .resourceIds("simpleCrud")// 设置可以访问的资源
                .authorizedGrantTypes("authorization_code","password", "refresh_token")// 允许的授权类型(内部为枚举)
                .autoApprove(false)// 跳转到授权页面
                .redirectUris("http://www.baidu.com");// 验证回调地址*//*

    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception{
        endpoints.authenticationManager(authenticationManager)
//                .authorizationCodeServices(new InMemoryAuthorizationCodeServices())//授权码管理
                .authorizationCodeServices(authorizationCodeServices(dataSource))
                .userDetailsService(userDetailsService)
                .tokenServices(tokenServices)
                .allowedTokenEndpointRequestMethods(HttpMethod.POST);
    }

    // 令牌的安全策略
    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        security.allowFormAuthenticationForClients()// 允许表单提交认证
                .tokenKeyAccess("permitAll()")
                .checkTokenAccess("permitAll()");
    }

    @Bean
    public AuthorizationCodeServices authorizationCodeServices(DataSource dataSource){
//        return new InMemoryAuthorizationCodeServices();
        return new JdbcAuthorizationCodeServices(dataSource);
    }




}
*/
